{extend name="public/common"}

{block name="style"}
<title>点对点教育VIP学员_信息录入</title>
<link rel="stylesheet" href="__HOME__/css/write/detail.css">
<style>
    .nomessage{
        text-align: center;
        position:fixed;
        top:50%;
        left:50%;
        -webkit-transform: translateY(-50%) translateX(-50%);
    }
    .nomessage>img{
        width:56%;
        margin-bottom:4vw;
    }
    .nomessage>span{
        font-size: 1.7rem;
        color:#ccc;
    }
    .tip {
        height: 40px;
        text-align: center;
        line-height: 40px;
        color: #c1c1c1;
        position: relative;
        margin-top: -21vw;
    }
    .comment .lists .list .mid .name {
        color: #999;
        font-size: 1.28rem;
        margin-left: 5vw;
        width: 80%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
</style>
{/block}
{block name="body"}
<div class="scroll"  style="position:absolute; overflow:scroll; -webkit-overflow-scrolling: touch; top:0; left:0; bottom:0; right:0" >
    <div class="comment">
        <div class="lists">
            {empty name="detail"}
            <div class="nomessage">
                <img src="__HOME__/images/sign/5.png" alt="" ><br>
                <span>抱歉，暂无记录</span>
            </div>
            {else/}
            {volist name="detail" id="co"}
            <div class="list clear">
                <div class="fl">
                    <img src="{$co.teacherid|get_header}" alt="用户" class="user">
                </div>
                <div class="fl mid">
                    <div class="name limit">{$co.teacher}老师</div>
                    <div class="content" >{$co.content}</div>
                    <div class="time">{$co.create_time|time_format="Y-m-d H:i"}</div>
                </div>
            </div>
            {/volist}
            {/empty}
        </div>
        <div class="tip"></div>
    </div>
</div>
{/block}

{block name="script"}
<script src="__HOME__/js/reset.js"></script>
<script>
    //关闭分享
    function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    }
    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
    var scrollNow = true;//判断下拉请求是否执行中.false为正在请求
    $(function(){
        $('title' ).text('点对点教育VIP学员_信息录入');
        if($(".list").length == 15){
            $('.tip').text('上拉加载更多');
            document.getElementsByClassName("scroll")[0].addEventListener('scroll',loadScroll);
        }else{
            document.getElementsByClassName("scroll")[0].removeEventListener("scroll",loadScroll);
            $('.tip').hide();
        }
    });
    //加载更多评论
    function loadScroll(){
        var len = $(".list" ).length;
        var id = '{$id}';
        var tip = $(".tip");
        if(scrollNow){
            scrollNow = false;
            $('.tip').text('上拉加载更多');
            $.ajax({
                type:"post",
                url:"{:Url('Write/moremore')}",
                data:{
                    id:id,
                    length:len
                },
                beforeSend: function(XMLHttpRequest){
                    $('.tip').text('加载中...');
                },
                success:function(data){
                    if(data.code == 1){
                        addComment(data);
                        if(data.data.length == 15){
                            $('.tip').text('上拉加载更多');
                        }else{
                            $('.tip').text('没有更多了');
                            document.getElementsByClassName("scroll")[0].removeEventListener("scroll",loadScroll);
                        }
                    }else{
                        $('.tip').text('没有更多了');
                        document.getElementsByClassName("scroll")[0].removeEventListener("scroll",loadScroll);
                    }
                    scrollNow = true;
                }
            })
        }
    }
    //添加评论
    function addComment(data){
        //is_like : 1为已点赞 0为未点赞
        var html = '';
        var lists = data.data;
        var len = lists.length;
        for(var i = 0; i< len;i++){
            var list = lists[i];
            html += '<div class="list clear">' +
                    '<div class="fl">' +
                    '<img src="' + list.header + '" alt="用户" class="user">' +
                    '</div>' +
                    '<div class="fl mid">' +
                    '<div class="name limit">'+list.teacher+'老师</div>'+
                    '<div class="content">' + list.content + '</div>' +
                    '<div class="time">' + list.time + '</div>' +
                    '</div>';
            html+=
                    '</div>';
        }
        $(".lists" ).append(html);
    }
</script>
{/block}